//
//  LTNewsCell.m
//  wangyiNews08
//
//  Created by 123 on 16/3/11.
//  Copyright © 2016年 Tsr. All rights reserved.
//

#import "LTNewsCell.h"
#import "LTNews.h"

#import "UIImageView+WebCache.h"


@interface LTNewsCell ()
// 新闻图片
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
// 新闻标题
@property (weak, nonatomic) IBOutlet UILabel *title;
// 新闻摘要
@property (weak, nonatomic) IBOutlet UILabel *digest;
// 跟帖数
@property (weak, nonatomic) IBOutlet UILabel *replyCount;

@property (strong, nonatomic) IBOutletCollection(UIImageView) NSArray *imgextraViews;


@end

@implementation LTNewsCell

- (void)setNews:(LTNews *)news {
    _news = news;
    
    self.title.text = _news.title;
    self.digest.text = _news.digest;
    self.replyCount.text = [NSString stringWithFormat:@"%@人跟帖",_news.replyCount];
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:news.imgsrc] placeholderImage:nil options:SDWebImageRetryFailed | SDWebImageLowPriority];
    
    // 遍历多图数组
    [news.imgextra enumerateObjectsUsingBlock:^(NSDictionary *  _Nonnull dict, NSUInteger idx, BOOL * _Nonnull stop) {
        
        UIImageView *imageView = self.imgextraViews[idx];
        
        NSString *imgsrc = dict[@"imgsrc"];
        
        [imageView sd_setImageWithURL:[NSURL URLWithString:imgsrc] placeholderImage:nil options:SDWebImageRetryFailed | SDWebImageLowPriority];
    }];
    
}

+ (NSString *)cellIdentifier:(LTNews *)news {
    if (news.imgextra) {
        return @"imageCell";
    } else if (news.imgType) {
        return @"bigCell";
    } else {
        return @"news";
    }
}

+ (CGFloat)cellHeight:(LTNews *)news {
    if (news.imgextra) {
        return 130;
    } else if (news.imgType){
        return 170;
    } else {
        return 80;
    }
}

@end
